<?php
/*
 * @美潮风
 * @功能说明：客户管理中心
 * @更新说明：暂无更新
 * @文件名 IndexController.class.php
 * @编码 UTF-8
 * @创建时间 2015-12-25 下午1:46:53
 * @创建人 XING
 */
namespace home\Controller;

use Think\Controller;

header("Content-type: text/html; charset=utf-8");

class IndexController extends ApibaseController
{
    function __construct() {
        parent::__construct();
        $this->_IntegerRoleModel = D('IntegerRole');
        $this->_UserController = new UserController();
    }

    /*
     * 用户列表
     * @date: 2015-6-2 上午11:04:55
     * @editor: XING
     */
    public function index() {
        /*参数初始化*/
        $page = I('get.page') ?: 1;
        $perpage = 10;
        $url = '';
        $list = M('CustEntity');
        $url = $output = $outtype = array();
        if (I('get.cust_mobile')) {
            $list = $list->where(array('cust_mobile' => I('get.cust_mobile')));
            $url['cust_mobile'] = I('get.cust_mobile');
        }
//        if (in_array(I('get.live_cate'), array('0','1','2','3'))) {
//            $list = $list->where(array('live_cate' => I('get.live_cate')));
//            $url['live_cate'] = I('get.live_cate');
//        }
        if (in_array(I('get.user_type'), array('1','2','3','4'))) {
            $list = $list->where(array('user_type' => I('get.user_type')));
            $url['user_type'] = I('get.user_type');
        }
        if(I('get.user_type') == 1){
            if (in_array(I('get.user_level'), array('1','2','3'))) {
                $list = $list->where(array('user_level' => I('get.user_level')));
                $url['user_level'] = I('get.user_level');
            }
        }else if(I('get.user_type') == 3){
            if (in_array(I('get.user_level2'), array('1','2','3'))) {
                $list = $list->where(array('user_level' => I('get.user_level2')));
                $url['user_level'] = I('get.user_level2');
            }
        }

        if (I('get.depart_id')) {
            $list = $list->where(array('depart_id' => I('get.depart_id')));
            $url['depart_id'] = I('get.depart_id');
        }

        $live_type = C('live_cate');
        $user_type = ['请选择','服务商','店家','员工','普通用户','all'=>'全部'];
        $custObject = clone $list;
//        $getData = $list->order(array('live_cate' => 'desc'))->page($page, $perpage)->select();
        $getData = $list->order(array('cust_id' => 'desc'))->page($page, $perpage)->select();
        foreach ($getData as $key => $value) {
            if($value['live_cate'] === '1'){
                unset($getData[$key]);
                break;
            }
        }
        $head = M('CustEntity')->where(['live_cate'=>1])->find();
        if($head){
            array_unshift($getData, $head);
        }
        //员工部门信息
        $depart = M('Department')->order('id desc')->select();
        $this->assign('depart',$depart);
        $this->assign('page', setPage($custObject->count(), $perpage, $page, '?' . http_build_query($url)));
        $this->assign('getData', $getData);
        $this->assign('user_type', $user_type);
        $this->assign('live_type', $live_type);

        $this->display('index/index');
    }
}